import { EcsEntity } from "ecs-ts";
import { gg } from "../../../Game";
import { Comp } from "./CompDef";
import { GpCfg } from "./GpCfgDef";

export enum EActionLogicState {
    doing = 0,
    finished = 1
}

export class HeroLogic {
    constructor(
        public logicType: string,
        public data: any,
        public target: { t: string, range?: number } = null,
        public subLogics: HeroLogic[] = []
    ) {
    }
}

export class HeroActionLogic extends HeroLogic {
    constructor(
        public state: EActionLogicState,
        public triggerTimeRatio: number,
        public logicType: string,
        public data: any,
        public target: { t: string, range?: number } = null,
        public subLogics: HeroLogic[] = []
    ) {
        super(logicType, data, target, subLogics);
    }
}

export enum EFindTargetConditionAttriType {
    force = "force",
    hpPercent = "hpPercent"
}

export enum EFindTargetMatchOpType {
    equals = "eq",
    notEquals = "neq",
    greater = "gt",
    less = "le",
    greaterOrEquals = "gteq",
    lessOrEquals = "leeq"
}

export enum EHeroTargetMatchType {
    parentLogic = "parentLogic",
    self = "self",
    actionTarget = "actionTarget",
    allEnemy = "allEnemy",
    enemyInTargetRange = "enemyInTargetRange"
}

export enum EHeroLogicType {
    findTargets = "findTargets",
    att = "att",
    aoe = "aoe",
    addBuff = "addBuff",
    cure = "cure",
    modifyAttri = "modifyAttri",
    playSound = "playSound",
    playEff = "playEff"

}

export class FindTargetCondition {
    constructor(public attriType: string, public matchType: string, public value: any) { }
}

export class HeroActionEventData {
    constructor(
        public entity: EcsEntity,
        public action: Comp.HeroAction,
        public target: EcsEntity
    ) { }
}


export class PlayEffEventData {
    constructor(
        public entity: EcsEntity,
        public logic: HeroLogic,
        public target: EcsEntity
    ) { }
}


export enum EHeroAttriModifyType {
    set = "set",
    add = "add",
}

export enum EHeroAttriOperationType {
    add = "add",
    mul = "mul",
}

export enum EHeroSpecialState {
    /**眩晕 */
    stun = 1,
}

export enum EHeroAttri {
    hp = "hp",
    atp = "atp",
    attSpeed = "ats",
}

/**英雄属性 */
export class HeroAttri {
    constructor(
        public id: EHeroAttri,
        // public baseValue: number,
        public modifyList: { add: number, mul: number }[] = [],
        public finalModify = { add: 0, mul: 1 }
    ) { }
}



/**英雄buff逻辑 */
export class HeroBuffLogic {
    constructor(
        public state: EActionLogicState,
        public triggerTimeRatio: number,
        public logicId: number,
        public data: any[]
    ) { }
}


/**拥有的技能 */
export class OwnSkill {
    constructor(
        public id: number,
        public nextCanUseTimeMs = 0,
        public priority: number = 0,
    ) {
        const cfg = gg.cfgById(GpCfg.Skill, this.id)
        this.priority = cfg.priority
    }
}


export namespace GpLogicDef {
    export class PlaySoundData{
        constructor (
            public sounds: string[],
        ){}
    }
}